from typing import List


class Skill:
    id = 0
    """技能id"""
    name = ""
    """技能名称"""
    icon = ""
    """技能图标"""
    masterLv = 0
    """精通等级"""
    maxLv = 0
    """上限等级"""
    requiredLv = 0
    """学习等级"""
    rangeLv = 1
    """学习间隔"""
    lv = 0
    """等级"""
    MP: List[int] = []
    """消耗MP"""
    SPCost = 0
    """消耗SP"""
    hasTP = False
    """消耗TP"""
    skillRatio = 1
    """技能面板倍率"""
    skillDamage = 1
    """技能技攻"""
    type = 0
    """主被动,1主动,0被动"""
    damage = False
    """是否有伤害"""
    cube = 0
    """无色消耗"""
    CD = 0
    """CD"""
    CDR = 1.0
    """CD缩减"""
    minLv = 0

    def effect(self, char, addLv = 0):
        pass

    def AddLv(self, x,  char={}):
        if self.lv > 0:
            addLv = min(self.maxLv, self.lv + x) - self.lv
            self.effect(char,addLv)
            self.lv += addLv

    def __init__(self):
        # 技能基础等级计算,角色等级+契约等级
        characterLv = 55 + 5
        if self.lv == 0:
            self.lv = min(int((characterLv - self.requiredLv) / self.rangeLv + 1), self.masterLv)
        pass


class ActiveSkill(Skill):
    type = 1
    damage = True
    hasTP = True

    data0 = []
    hit0 = 1
    power0 = 1
    dataType0 = ""

    TPCost = 0
    TPLv = 0
    maxTPLv = 0
    masterTPLv = 0
    growthTP = 0
    TPRequireLv = 55
    TPRangeLv = 5
    TPLearnMax = 0

    damageType = '物理'
    ElementA = {'火': False, '冰': False, '光': False, '暗': False}

    def TPRatio(self, char={}):
        return 1 + self.TPLv * self.TPGrowth

    def AddTPLv(self, x, char={}):
        if self.TPLv > 0:
            self.TPLv = min(self.maxTPLv, self.TPLv + x)

    def BasicData(self, char={}):
        res = 0.0
        for i in range(0, 10):
            data = getattr(self, "data{}".format(i), [])
            if self.lv < len(data) and self.lv > 0:
                hit = getattr(self, f"hit{i}", 1)
                power = getattr(self, f"power{i}")
                res += data[self.lv] * hit * power
        return res

    def LastCD(self, char={}):
        return self.CD * self.CDR

    def __init__(self):
        super().__init__()
        characterLv = 55 + 5
        if self.requiredLv <= 10:
            self.TPRequireLv = 50
        else:
            self.TPRequireLv = 55
        if self.masterTPLv > 0 and self.TPLearnMax == 0:
            self.TPLearnMax = min(int((characterLv - self.TPRequireLv) / self.TPRangeLv + 1), self.masterTPLv)

class PassiveSkill(Skill):
    type = 0
    damage = False
